<template>
  <div>
    <el-container>
      <el-aside
        :width="isCollapse ? '64px' : '240px'"
        style="transition: .5s;"
      >
        <div class="header_logo">
          <h1 v-show="isCollapse === false">XXX后台管理系统</h1>
          <img
            src="../assets/h_logo.png"
            v-show="isCollapse === true"
          >
        </div>
        <el-menu
          :default-active="$route.path"
          class="el-menu-vertical-demo"
          :collapse="isCollapse"
          :collapse-transition="false"
          background-color="#25262f"
          text-color="#fff"
          active-text-color="#ffd04b"
          :unique-opened="true"
          router
        >
          <el-submenu index='1'>
            <template slot="title">
              <Icon
                size="26"
                style="margin-right:10px"
              >
                <ViewCompactRound />
              </Icon>
              <span slot="title">Element-Ui</span>
            </template>
            <el-menu-item index="/homepage/table">完整功能表格</el-menu-item>
            <el-menu-item index="/homepage/edittable">行内编辑表格</el-menu-item>
            <el-menu-item index="/homepage/demo">DEMO</el-menu-item>
          </el-submenu>
          <el-submenu index='2'>
            <template slot="title">
              <Icon
                size="26"
                style="margin-right:10px"
              >
                <TextFieldsRound />
              </Icon>
              <span slot="title">富文本编辑器</span>
            </template>
            <el-menu-item index="/homepage/tinymce">tinymce富文本</el-menu-item>
          </el-submenu>
          <el-submenu index='3'>
            <template slot="title">
              <i class="el-icon-platform-eleme"></i>
              <span slot="title">卡片</span>
            </template>
            <el-menu-item index="/homepage/mycard">静态卡片</el-menu-item>
            <el-menu-item index="/homepage/ganttchart">甘特图</el-menu-item>
          </el-submenu>
          <el-submenu index='4'>
            <template slot="title">
              <i class="el-icon-platform-eleme"></i>
              <span slot="title">3D</span>
            </template>
            <el-menu-item index="/homepage/three">threeJS</el-menu-item>
          </el-submenu>
        </el-menu>
      </el-aside>
      <el-main>
        <el-header>
          <div
            class="header_main"
            @click="collapseIcons"
          >
            <i
              class="el-icon-s-unfold"
              v-show="isCollapse === true"
            ></i>
            <i
              class="el-icon-s-fold"
              v-show="isCollapse === false"
            ></i>
          </div>
          <div class="login_out">
            <div class="gieet">
              <a
                href="https://gitee.com/zhang-yunxin/xin-app"
                target="view_window"
              >
                <img
                  src="../assets/gieet.png"
                  style="width: 16px;height: 16px"
                />
              </a>
            </div>
            <div
              class="full-screen"
              @click="fullScreen()"
            >
              <Icon
                size="26"
                v-if="fullscreen === false"
              >
                <FullscreenOutlined />
              </Icon>
              <Icon
                size="26"
                v-else
              >
                <FullscreenExitOutlined />
              </Icon>
            </div>
            <div
              class="avatar"
              @click="avatarImg"
            >
              <img :src="circleUrl" />
            </div>
            <div class="out_login">
              <el-dropdown
                :hide-on-click="false"
                trigger="click"
                @command="handleCommand"
              >
                <span class="el-dropdown-link">
                  青木<i class="el-icon-arrow-down el-icon--right"></i>
                </span>
                <el-dropdown-menu slot="dropdown">
                  <el-dropdown-item command="a">个人中心</el-dropdown-item>
                  <el-dropdown-item
                    command="b"
                    divided
                  >退出登录</el-dropdown-item>
                </el-dropdown-menu>
              </el-dropdown>
            </div>
          </div>
        </el-header>
        <div class="router_view_main">
          <router-view></router-view>
        </div>
      </el-main>
    </el-container>
  </div>
</template>

<script>
// 图标库
import { FullscreenExitOutlined, FullscreenOutlined, ViewCompactRound, TextFieldsRound, AnimationSharp } from '@v2icons/material'
import { Icon } from '@v2icons/utils'
// 全屏功能
export default {
  components: {
    Icon,
    FullscreenExitOutlined,
    FullscreenOutlined,
    ViewCompactRound,
    TextFieldsRound,
    AnimationSharp
  },
  data () {
    return {
      isCollapse: false, // aside折叠
      circleUrl: require('../assets/touxiang.png'), // 头像地址,
      visible: false, // 退出登录弹框
      fullscreen: false // 默认全屏
    }
  },
  methods: {
    // 点击左侧菜单展开
    collapseIcons () {
      this.isCollapse = !this.isCollapse
    },
    // 点击全屏展示
    fullScreen () {
      const element = document.documentElement
      if (this.fullscreen) {
        if (document.exitFullscreen) {
          document.exitFullscreen()
        } else if (document.webkitCancelFullScreen) {
          document.webkitCancelFullScreen()
        } else if (document.mozCancelFullScreen) {
          document.mozCancelFullScreen()
        } else if (document.msExitFullscreen) {
          document.msExitFullscreen()
        }
      } else {
        if (element.requestFullscreen) {
          element.requestFullscreen()
        } else if (element.webkitRequestFullScreen) {
          element.webkitRequestFullScreen()
        } else if (element.mozRequestFullScreen) {
          element.mozRequestFullScreen()
        } else if (element.msRequestFullscreen) {
          // IE11
          element.msRequestFullscreen()
        }
      }
      this.fullscreen = !this.fullscreen
    },
    // 退出
    handleCommand (command) {
      if (command === 'a') {
        this.$router.push('/homepage/personalcenter')
      } else if (command === 'b') {
        this.$router.push('/login')
        window.sessionStorage.clear()
      }
    },
    // 点击头像跳转
    avatarImg () {
      this.$router.push('/homepage/personalcenter')
    }
  }
}
</script>

<style lang="less" scoped>
.el-header,
.el-footer {
  height: 6vh;
  padding: 0 !important;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #fff;
  border-bottom: 1px solid rgb(236, 236, 236);
  .header_main {
    width: 80px;
    height: 100%;
    text-align: center;
    line-height: 65px;
    cursor: pointer;
    .el-icon-s-fold,
    .el-icon-s-unfold {
      font-size: 30px !important;
    }
  }
  .login_out {
    margin-right: 20px;
    height: 60px;
    display: flex;
    align-items: center;
    justify-content: right;
    .avatar {
      border-radius: 25px;
      img {
        width: 50px;
        height: 50px;
        margin: 0 10px;
        border-radius: 25px;
        cursor: pointer;
      }
    }
    .out_login {
      display: flex;
      align-items: center;
      height: 6vh;
      .el-dropdown {
        margin: 0 10px;
        cursor: pointer;
      }
    }
  }
}

.out_login:hover {
  background: #f2f2f2;
}
.header_main:hover {
  background: #f2f2f2;
}
.el-menu {
  border-right: none;
  .el-menu-item {
    background: #191b21 !important;
  }
}
.el-menu .el-menu-item.is-active {
  border-right: 4px solid #ffd04b;
}
.el-aside {
  background-color: #25262f;
  height: 100vh;
  overflow: hidden;
  .header_logo {
    width: 240px;
    height: 60px;
    border-right: 1px solid #999;
    box-sizing: border-box;
    background: #3b3d49;
    transition: 0.5s;
    h1 {
      color: #fff;
      text-align: center;
      line-height: 60px;
    }
    img {
      width: 40px;
      height: 40px;
      padding: 10px;
    }
  }
}

.el-main {
  background-color: #f8f7fc;
  height: 100vh;
  padding: 0 !important;
  .router_view_main {
    padding: 10px;
    height: calc(100% - 80px);
  }
}
.xicon {
  cursor: pointer;
}
.full-screen {
  margin: 0 10px;
}
/deep/.el-icon-platform-eleme {
  color: #fff;
}
</style>
